<?php
header("Content-Type:text/html; charset=utf-8");
include 'includes/utilities.php';
$link = OpenDB();
$search = mysql_real_escape_string($_POST["q"]);
$search = str_ireplace("á", "%", $search);
$search = str_ireplace("é", "%", $search);
$search = str_ireplace("í", "%", $search);
$search = str_ireplace("ó", "%", $search);
$search = str_ireplace("ú", "%", $search);
$search = str_ireplace("ñ", "%", $search);
$query = "select id_paciente as id, concat(apellido, ', ',nombre ) as nombre from paciente 
    where nombre like '%" . $search . "%' or apellido like '%" . $search . "%'";
$pacientes = GetSQL($query);
$valores = "";
if ($pacientes)
{

    foreach ($pacientes as $paciente)
    {
        $valores .= '{"id":"' . $paciente["id"] . '", "name":"' . $paciente["nombre"] . '"},';
    }
    $valores = rtrim($valores, ",");
} 
?>
[<?= $valores ?>]
